function login() {
    const name = document.getElementById("name").value;
    const password = document.getElementById("password").value;
    ajax(`/account/login?name=${name}&password=${password}`, {}, function (data) {
        if (data.code === 0) {
            localStorage.setItem("Authorization", data.data);
            window.top.location.href = "/index.html";
        } else {
            let span = document.getElementById("error_message");
            span.style.display = "";
            span.innerText = `${data.message}`;
        }
    });
}

document.getElementById("password").addEventListener("keydown", function (e) {
    if (e.key === "Enter") {
        e.preventDefault(); // optional, stops form submit
        login();
    }
});
window.onload = function () {
    document.getElementById("name").focus();
}